package com.woniuxy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.work.framework.pojo.Bidder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: wanghao
 * @Date: 2019/9/18 11:59
 */
@Mapper
@Repository
public interface BidderMapper extends BaseMapper<Bidder> {

    /**
     * 冻结押金
     * @param bidder
     * @return
     */
    @Update("update  bidder set p_status = #{pStatus} where aid = #{aid}")
    int updateBidderByAid(Bidder bidder);

    /**
     * 查询需要解冻的biider信息
     * @param bidder
     * @return
     */
    @Select("select * from bidder where aid = #{aid} and uid != #{uid}")
    List<Bidder> selectFreezeBidder(Bidder bidder);

    /**
     * 解冻除竞拍成功的人的状态
     * @param bidder
     * @return
     */
    @Update("update  bidder set p_status = #{pStatus} where aid = #{aid} and uid != #{uid}")
    int updateBidderByAidAndUid(Bidder bidder);

    /**
     * 查找竞拍人的uid集合
     * @param aid
     * @return
     */
    @Select("select uid from bidder where aid = #{aid}")
    List<Integer> selectUidByAid(Integer aid);


    /**
     * 查找bidder通过uid和aid
     * @param bidder
     * @return
     */
    @Select("select * from bidder where aid = #{aid} and uid = #{uid}")
    Bidder findBidder(Bidder bidder);

    /**
     * 通过aid查找bidder
     * @param aid
     * @return
     */
    @Select("select * from bidder where aid = #{aid}")
    List<Bidder> selectBidderByAid(Integer aid);

    /**
     * 通过uid查找用户可退的押金
     * @param uid
     * @return
     */
    @Select("select * from bidder where uid = #{uid}")
    List<Bidder> selectBidderByUid(Integer uid);

    /**
     * 修改用户的押金状态
     * @param bidder
     * @return
     */
    @Update("update  bidder set p_status = #{pStatus} where aid = #{aid} and uid = #{uid}")
    Integer updateBidderByUid(Bidder bidder);
}
